package jumpingnotes.model.entity;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import net.jf.lucene.analysis.mmseg.MMSegAnalyzer;

import org.hibernate.search.annotations.Analyzer;
import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.Store;

@Entity
@Table(name = "group", catalog = "jumping_notes")
@Indexed
@Analyzer(impl = MMSegAnalyzer.class)
public class Group implements java.io.Serializable
{

	private Integer groupId;
	private Member member;
	private String name;
	private String intro;
	private String image;
	private String tag;
	private Integer publicFlag;
	private Integer memberCount;
	private Date createTime;
	private Date updateTime;
	private Set<GroupTopic> groupTopics = new HashSet<GroupTopic>(0);
	private Set<GroupMemberConfirm> groupMemberConfirms = new HashSet<GroupMemberConfirm>(0);
	private Set<GroupMember> groupMembers = new HashSet<GroupMember>(0);

	public Group()
	{
	}

	public Group(Member member, String name)
	{
		this.member = member;
		this.name = name;
	}

	public Group(Member member, String name, String intro, String image, String tag, Integer publicFlag,
			Integer memberCount, Date createTime, Date updateTime, Set<GroupTopic> groupTopics,
			Set<GroupMemberConfirm> groupMemberConfirms, Set<GroupMember> groupMembers)
	{
		this.member = member;
		this.name = name;
		this.intro = intro;
		this.image = image;
		this.tag = tag;
		this.publicFlag = publicFlag;
		this.memberCount = memberCount;
		this.createTime = createTime;
		this.updateTime = updateTime;
		this.groupTopics = groupTopics;
		this.groupMemberConfirms = groupMemberConfirms;
		this.groupMembers = groupMembers;
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "group_id", unique = true, nullable = false)
	@DocumentId
	public Integer getGroupId()
	{
		return this.groupId;
	}

	public void setGroupId(Integer groupId)
	{
		this.groupId = groupId;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "member_id_creator", nullable = false)
	public Member getMember()
	{
		return this.member;
	}

	public void setMember(Member member)
	{
		this.member = member;
	}

	@Column(name = "name", nullable = false, length = 100)
	@Field(index = Index.TOKENIZED, store = Store.NO)
	public String getName()
	{
		return this.name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	@Column(name = "intro", length = 65535)
	@Field(index = Index.TOKENIZED, store = Store.NO)
	public String getIntro()
	{
		return this.intro;
	}

	public void setIntro(String intro)
	{
		this.intro = intro;
	}

	@Column(name = "image")
	public String getImage()
	{
		return this.image;
	}

	public void setImage(String image)
	{
		this.image = image;
	}

	@Column(name = "tag")
	@Field(index = Index.TOKENIZED, store = Store.NO)
	public String getTag()
	{
		return this.tag;
	}

	public void setTag(String tag)
	{
		this.tag = tag;
	}

	@Column(name = "public_flag")
	public Integer getPublicFlag()
	{
		return this.publicFlag;
	}

	public void setPublicFlag(Integer publicFlag)
	{
		this.publicFlag = publicFlag;
	}

	@Column(name = "member_count")
	public Integer getMemberCount()
	{
		return this.memberCount;
	}

	public void setMemberCount(Integer memberCount)
	{
		this.memberCount = memberCount;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "create_time", length = 19)
	public Date getCreateTime()
	{
		return this.createTime;
	}

	public void setCreateTime(Date createTime)
	{
		this.createTime = createTime;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "update_time", length = 19)
	public Date getUpdateTime()
	{
		return this.updateTime;
	}

	public void setUpdateTime(Date updateTime)
	{
		this.updateTime = updateTime;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "group")
	public Set<GroupTopic> getGroupTopics()
	{
		return this.groupTopics;
	}

	public void setGroupTopics(Set<GroupTopic> groupTopics)
	{
		this.groupTopics = groupTopics;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "group")
	public Set<GroupMemberConfirm> getGroupMemberConfirms()
	{
		return this.groupMemberConfirms;
	}

	public void setGroupMemberConfirms(Set<GroupMemberConfirm> groupMemberConfirms)
	{
		this.groupMemberConfirms = groupMemberConfirms;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "group")
	public Set<GroupMember> getGroupMembers()
	{
		return this.groupMembers;
	}

	public void setGroupMembers(Set<GroupMember> groupMembers)
	{
		this.groupMembers = groupMembers;
	}

}
